﻿using System.Web.Mvc;
using BusinessLogicLayer;

namespace MvcApplication.Controllers
{
    using System;

    using DataAccessLayer;

    /// <summary>
    /// controller for responding to display task dashboard 
    /// </summary>
    public class HomeController : Controller
    {
        private static TasksDashBoard tasksDashBoard;
        /// <summary>
        /// displaying task dashboard
        /// </summary>
        /// <returns>view</returns>
        public ActionResult Index()
        {
            tasksDashBoard = (TasksDashBoard)DashBoardManager.CreateDashBoard(LayerType.TasksDashBoard);
            return View(tasksDashBoard);
        }
        /// <summary>
        /// displaying details for task 
        /// </summary>
        /// <param name="name">name of the task</param>
        /// <returns>partial view</returns>
        [HttpPost]
        public ActionResult GetDetails(string name)
        {
            var task = (Task)tasksDashBoard.GetItemByName(name);
            return View(task);
        }
        /// <summary>
        /// adding new comment to database and displaying it on view
        /// </summary>
        /// <param name="taskId">id of current task</param>
        /// <param name="body">the body of new comment</param>
        /// <returns>comment's view</returns>
        [HttpPost]
        public ActionResult AddComment(int taskId, string body)
        {
            var comment = tasksDashBoard.AddNewComment(taskId, HttpContext.User.Identity.Name, body, DateTime.Now);
            return View(comment);
        }
    }
}
